package com.tanhua.server.controller;

import com.tanhua.model.vo.ContactVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "消息相关接口")
@RestController
@RequestMapping("/messages")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @ApiOperation("通过环信id获取用户信息")
    @GetMapping("/userinfo")
    public ResponseEntity getUserInfoByHuanxinId(String huanxinId) {
        UserInfoVo userInfoVo = messageService.getUserInfoByHuanxinId(huanxinId);
        return ResponseEntity.ok(userInfoVo);
    }

    @ApiOperation("联系人添加")
    @PostMapping("contacts")
    public ResponseEntity addContacts(@RequestBody Map<String,String> params) {
        messageService.makeFriends(params);
        return ResponseEntity.ok(null);
    }

    @ApiOperation("联系人列表")
    @GetMapping("contacts")
    public ResponseEntity contactList(@RequestParam(defaultValue = "1") Long page,
                                      @RequestParam(defaultValue = "10", name = "pagesize") Long pageSize,
                                      String keyword) {
        PageResult<ContactVo> pageResult = messageService.contactList(page, pageSize, keyword);
        return ResponseEntity.ok(pageResult);
    }
}
